//Sun May  2 10:48:19 CDT 2010
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class RobotSimulation
{
public:
	int cellsVisited(string program, int times)
	{
		set<pair<int, int> > v;
		int x = 0;
		int y = 0;
		v.insert(make_pair(x, y));
		int count = 0;
		int ret = 1;
		for (int i = 0; i < min(1000, times); i++)
		{
			count = 0;
			for (int j = 0; j < program.size(); j++)
			{
				switch (program[j])
				{
				case 'U':
					y--;
					break;
				case 'L':
					x--;
					break;
				case 'R':
					x++;
					break;
				case 'D':
					y++;
					break;
				}
				if (v.count(make_pair(x, y)) == 0)
				{
					ret++;
					count++;
					v.insert(make_pair(x, y));
				}
			}
		}
		return ret += count * (times - min(1000, times));
	}
};
/*
 * Take care of the iterative, after n times, the situation will be the same.
 * */
